﻿<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    
    <style type="text/css">
        .silverlightHost { width: 640px; height: 480px; }
        .text { font: 8pt Trebuchet MS }
        
        body 
        { 
        	font: 11pt Trebuchet MS;
            padding-top: 72px;
            text-align: center 
        }

    </style>
    <script type="text/javascript" src="./js/Silverlight.js"></script>
    <script type="text/javascript" src="./js/TestPage.html.js"></script>
    <style type="text/css">
        .silverlightHost { width: 800px; height: 600px; }
    </style>
    <script type="text/javascript" src="./js/xmlhelper.js" ></script>
    <script type="text/javascript" src="./js/message.js" ></script>
    <script type="text/javascript">
   
    function GetData(g)
    {
        guid = g;
        Service.GetMsg(guid, OnRequestCompleteGet);
    }

    function OnRequestCompleteGet(result)
    {
        var ElePlayerNames = document.getElementById("PlayerNames");
        var xmldoc = XML.parse(result);
        var msg = xmldoc.getElementsByTagName("message")[0];
        if (msg.getAttribute("type") == "playerList"){
            var players = msg.getElementsByTagName("player")
            var playerNames = "";
             for(var r=0; r < players.length; r++) {
                var player = players[r];
                playerNames = playerNames + player.firstChild.data +';';                
            }
            ElePlayerNames.innerHTML = playerNames;
        }
        //alert(result);
    }
    
    function RegisterClick()
    {
        var yourname = document.getElementById("DisplayName");
        if (yourname.value == "")
        {
            alert("Please input your name first");
            return ;
        }
        MessageController.OnRecvMsg = OnRequestCompleteGet;
        MessageController.Join("<message type=\"newuser\"><user>"+yourname.value +"</user></message>");
    }
    
    </script>

</head>
<body >
    <a href="Silverlight.1.1.AlphaRefresh.exe">Silverlight1.1</a>
    <div id="SilverlightControlHost" class="silverlightHost" >
        <script type="text/javascript">
            createSilverlight();
        </script>
    </div>
    <form id="Form1" runat="server">
        <asp:ScriptManager runat="server" ID="scriptManager">
            <Services>
                <asp:ServiceReference path="~/Service.asmx" />
            </Services>
        </asp:ScriptManager>
        
        <div style="text-align: left; left:100px; width: 600px; height:auto;">
            Your Display Name:
            <input id="DisplayName" type="text" />
            <input id="RegisterButton" type="button" value="Register" onclick="RegisterClick()" />
        </div>
        
        <table style="width: 800px; height: 480px">
            <tr>
                <td style="width: 640px; height: 480px">

                </td>
                <td style="width: 160px; height: 480px" >
                    <textarea style="vertical-align:top;" id="PlayerNames" cols="20" rows="8"></textarea>
                </td>
            </tr>
        </table>

    </form>

</body>
</html>
